package com.ruoyi.web.controller.business.sundry;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.business.base.PageParam;
import com.ruoyi.business.sundry.domain.vo.JbProductRecipeVo;
import com.ruoyi.web.core.JoR;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.sundry.domain.JbProductRecipe;
import com.ruoyi.business.sundry.service.JbProductRecipeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品配方 Controller
 *
 * @author ruoyi
 * @date 2024-10-11
 */
@Api("商品配方")
@RestController
@RequestMapping("/product_recipe")
public class JbProductRecipeController extends BaseController
{
    @Autowired
    private JbProductRecipeService service;

    /**
     * 查询商品配方列表
     */
    @ApiOperation("查询商品配方列表")
    @PreAuthorize("@ss.hasPermi('product_recipe:list')")
    @GetMapping("/list")
    public TableDataInfo list(PageParam page, JbProductRecipe jbProductRecipe)
    {
        IPage<JbProductRecipeVo> iPage = service.pageList(page, jbProductRecipe);
        return JoR.getDataTable(iPage);
    }

    /**
     * 导出商品配方列表
     */
    @ApiOperation("导出商品配方列表")
    @PreAuthorize("@ss.hasPermi('product_recipe:export')")
    @Log(title = "商品配方", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PageParam page, JbProductRecipe jbProductRecipe)
    {
        LambdaQueryWrapper<JbProductRecipe> select = new LambdaQueryWrapper<>();
        IPage<JbProductRecipe> iPage = service.page(page.b(), select);

        List<JbProductRecipe> list = iPage.getRecords();
        ExcelUtil<JbProductRecipe> util = new ExcelUtil<JbProductRecipe>(JbProductRecipe.class);
        util.exportExcel(response, list, "商品配方数据");
    }

    /**
     * 获取商品配方详细信息
     */
    @ApiOperation("获取商品配方详细信息")
    @PreAuthorize("@ss.hasPermi('product_recipe:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(service.getById(id));
    }

    /**
     * 新增商品配方
     */
    @ApiOperation("新增商品配方")
    @PreAuthorize("@ss.hasPermi('product_recipe:add')")
    @Log(title = "商品配方", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JbProductRecipe jbProductRecipe)
    {
        return toAjax(service.save(jbProductRecipe));
    }

    /**
     * 修改商品配方
     */
    @ApiOperation("修改商品配方")
    @PreAuthorize("@ss.hasPermi('product_recipe:edit')")
    @Log(title = "商品配方", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JbProductRecipe jbProductRecipe)
    {
        return toAjax(service.updateById(jbProductRecipe));
    }

    /**
     * 删除商品配方
     */
    @ApiOperation("删除商品配方")
    @PreAuthorize("@ss.hasPermi('product_recipe:remove')")
    @Log(title = "商品配方", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(service.removeByIds(Arrays.asList(ids)));
    }
    /**
     * 获取商品配方详细信息
     */
    @ApiOperation("获取商品配方详细信息")
    @PreAuthorize("@ss.hasPermi('product_recipe:query')")
    @GetMapping(value = "/details/{id}")
    public AjaxResult getDetails(@PathVariable("id") Long id)
    {
        return success(service.getDetails(id));
    }
    /**
     * 修改商品配方
     */
    @ApiOperation("修改商品配方")
    @PreAuthorize("@ss.hasPermi('product_recipe:edit')")
    @Log(title = "商品配方", businessType = BusinessType.UPDATE)
    @PutMapping("/editInfo")
    public AjaxResult editInfo(@RequestBody JbProductRecipeVo jbProductRecipeVo)
    {
        return toAjax(service.editInfo(jbProductRecipeVo));
    }
    /**
     * 添加商品配方
     */
    @ApiOperation("添加商品配方")
    @PreAuthorize("@ss.hasPermi('product_recipe:add')")
    @Log(title = "商品配方", businessType = BusinessType.UPDATE)
    @PutMapping("/addInfo")
    public AjaxResult addInfo(@RequestBody JbProductRecipeVo jbProductRecipeVo)
    {
        return toAjax(service.addInfo(jbProductRecipeVo));
    }
}
